home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / GCC / GNU / lib / g++-include / CursesW.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-31  |  13.7 KB  |  591 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1989 Free Software Foundation
  5.     written by Eric Newton (newton@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #ifndef _CursesWindow_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define _CursesWindow_h
  25.  
  26. #include   <_G_config.h>
  27. #if _G_HAVE_CURSES
  28. #include   <curses.h>
  29.  
  30. /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
  31.    Undefine it here, because CursesWindow uses lines as a method.  */
  32. #undef lines
  33.  
  34. // "Convert" macros to inlines, if needed.
  35. #ifdef addch
  36. inline int (addch)(char ch)  { return addch(ch); }
  37. #undef addch
  38. #endif
  39. #ifdef addstr
  40. /* The (char*) cast is to hack around missing const's */
  41. inline int (addstr)(const char * str)  { return addstr((char*)str); }
  42. #undef addstr
  43. #endif
  44. #ifdef clear
  45. inline int (clear)()  { return clear(); }
  46. #undef clear
  47. #endif
  48. #ifdef clearok
  49. inline int (clearok)(WINDOW* win, int bf)  { return clearok(win, bf); }
  50. #undef clearok
  51. #else
  52. extern "C" int clearok(WINDOW*, int);
  53. #endif
  54. #ifdef clrtobot
  55. inline int (clrtobot)()  { return clrtobot(); }
  56. #undef clrtobot
  57. #endif
  58. #ifdef clrtoeol
  59. inline int (clrtoeol)()  { return clrtoeol(); }
  60. #undef clrtoeol
  61. #endif
  62. #ifdef delch
  63. inline int (delch)()  { return delch(); }
  64. #undef delch
  65. #endif
  66. #ifdef deleteln
  67. inline int (deleteln)()  { return deleteln(); }
  68. #undef deleteln
  69. #endif
  70. #ifdef erase
  71. inline int (erase)()  { return erase(); }
  72. #undef erase
  73. #endif
  74. #ifdef flushok
  75. inline int (flushok)(WINDOW* _win, int _bf)  { return flushok(_win, _bf); }
  76. #undef flushok
  77. #else
  78. #define _no_flushok
  79. #endif
  80. #ifdef getch
  81. inline int (getch)()  { return getch(); }
  82. #undef getch
  83. #endif
  84. #ifdef getstr
  85. inline int (getstr)(char *_str)  { return getstr(_str); }
  86. #undef getstr
  87. #endif
  88. #ifdef getyx
  89. inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
  90. #undef getyx
  91. #endif
  92. #ifdef inch
  93. inline int (inch)()  { return inch(); }
  94. #undef inch
  95. #endif
  96. #ifdef insch
  97. inline int (insch)(char c)  { return insch(c); }
  98. #undef insch
  99. #endif
  100. #ifdef insertln
  101. inline int (insertln)()  { return insertln(); }
  102. #undef insertln
  103. #endif
  104. #ifdef leaveok
  105. inline int (leaveok)(WINDOW* win, int bf)  { return leaveok(win, bf); }
  106. #undef leaveok
  107. #else
  108. extern "C" int leaveok(WINDOW* win, int bf);
  109. #endif
  110. #ifdef move
  111. inline int (move)(int x, int y)  { return move(x, y); }
  112. #undef move
  113. #endif
  114. #ifdef refresh
  115. inline int (rfresh)()  { return refresh(); }
  116. #undef refresh
  117. #endif
  118. #ifdef scrollok
  119. inline int (scrollok)(WINDOW* win, int bf)  { return scrollok(win, bf); }
  120. #undef scrollok
  121. #else
  122. #ifndef hpux
  123. extern "C" int scrollok(WINDOW*, int);
  124. #else
  125. extern "C" int scrollok(WINDOW*, char);
  126. #endif
  127. #endif
  128. #ifdef standend
  129. inline int (standend)()  { return standend(); }
  130. #undef standend
  131. #endif
  132. #ifdef standout
  133. inline int (standout)()  { return standout(); }
  134. #undef standout
  135. #endif
  136. #ifdef wstandend
  137. inline int (wstandend)(WINDOW *win)  { return wstandend(win); }
  138. #undef wstandend
  139. #endif
  140. #ifdef wstandout
  141. inline int (wstandout)(WINDOW *win)  { return wstandout(win); }
  142. #undef wstandout
  143. #endif
  144. #ifdef winch
  145. inline int (winch)(WINDOW* win) { return winch(win); }
  146. #undef winch
  147. #endif
  148.  
  149. /* deal with conflicting macros in ncurses.h  which is SYSV based*/
  150. #ifdef box
  151. inline (box)(WINDOW* win, chtype v, chtype h) {return box(win, v, h); }
  152. #undef box
  153. #endif
  154. #ifdef scroll
  155. inline (scroll)(WINDOW* win) { return scroll(win); }
  156. #undef scroll
  157. #endif
  158. #ifdef touchwin
  159. inline (touchwin)(WINDOW* win) { return touchwin(win); }
  160. #undef touchwin
  161. #endif
  162.  
  163. #ifdef mvwaddch
  164. inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
  165. { return mvwaddch(win, y, x, ch); }
  166. #undef mvwaddch
  167. #endif
  168. #ifdef mvwaddstr
  169. inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
  170. { return mvwaddstr(win, y, x, (char*)str); }
  171. #undef mvwaddstr
  172. #endif
  173. #ifdef mvwdelch
  174. inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
  175. #undef mvwdelch
  176. #endif
  177. #ifdef mvwgetch
  178. inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
  179. #undef mvwgetch
  180. #endif
  181. #ifdef mvwgetstr
  182. inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
  183. {return mvwgetstr(win,y,x, str);}
  184. #undef mvwgetstr
  185. #endif
  186. #ifdef mvwinch
  187. inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
  188. #undef mvwinch
  189. #endif
  190. #ifdef mvwinsch
  191. inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
  192. { return mvwinsch(win, y, x, c); }
  193. #undef mvwinsch
  194. #endif
  195.  
  196. #ifdef mvaddch
  197. inline int (mvaddch)(int y, int x, char ch)
  198. { return mvaddch(y, x, ch); }
  199. #undef mvaddch
  200. #endif
  201. #ifdef mvaddstr
  202. inline int (mvaddstr)(int y, int x, const char * str)
  203. { return mvaddstr(y, x, (char*)str); }
  204. #undef mvaddstr
  205. #endif
  206. #ifdef mvdelch
  207. inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
  208. #undef mvdelch
  209. #endif
  210. #ifdef mvgetch
  211. inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
  212. #undef mvgetch
  213. #endif
  214. #ifdef mvgetstr
  215. inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
  216. #undef mvgetstr
  217. #endif
  218. #ifdef mvinch
  219. inline int (mvinch)(int y, int x) { return mvinch(y, x);}
  220. #undef mvinch
  221. #endif
  222. #ifdef mvinsch
  223. inline int (mvinsch)(int y, int x, char c)
  224. { return mvinsch(y, x, c); }
  225. #undef mvinsch
  226. #endif
  227.  
  228. /*
  229.  *
  230.  * C++ class for windows.
  231.  *
  232.  *
  233.  */
  234.  
  235. class CursesWindow 
  236. {
  237. protected:
  238.   static int     count;           // count of all active windows:
  239.                                   //   We rely on the c++ promise that
  240.                                   //   all otherwise uninitialized
  241.                                   //   static class vars are set to 0
  242.  
  243.   WINDOW *       w;               // the curses WINDOW
  244.  
  245.   int            alloced;         // true if we own the WINDOW
  246.  
  247.   CursesWindow*  par;             // parent, if subwindow
  248.   CursesWindow*  subwins;         // head of subwindows list
  249.   CursesWindow*  sib;             // next subwindow of parent
  250.  
  251.   void           kill_subwindows(); // disable all subwindows
  252.  
  253. public:
  254.                  CursesWindow(WINDOW* &window);   // useful only for stdscr
  255.  
  256.                  CursesWindow(int lines,          // number of lines
  257.                               int cols,           // number of columns
  258.                               int begin_y,        // line origin
  259.                               int begin_x);       // col origin
  260.  
  261.                  CursesWindow(CursesWindow& par,  // parent window
  262.                               int lines,          // number of lines
  263.                               int cols,           // number of columns
  264.                               int by,             // absolute or relative
  265.                               int bx,             //   origins:
  266.                               char absrel = 'a'); // if `a', by & bx are
  267.                                                   // absolute screen pos,
  268.                                                   // else if `r', they are
  269.                                                   // relative to par origin
  270.                 ~CursesWindow();
  271.  
  272. // terminal status
  273.   int            lines(); // number of lines on terminal, *not* window
  274.   int            cols();  // number of cols  on terminal, *not* window
  275.  
  276. // window status
  277.   int            height(); // number of lines in this window
  278.   int            width();  // number of cols in this window
  279.   int            begx();   // smallest x coord in window
  280.   int            begy();   // smallest y coord in window
  281.   int            maxx();   // largest  x coord in window
  282.   int            maxy();   // largest  x coord in window
  283.  
  284. // window positioning
  285.   int            move(int y, int x);
  286.  
  287. // coordinate positioning
  288.   void           getyx(int& y, int& x);
  289.   int            mvcur(int sy, int ey, int sx, int ex);
  290.  
  291. // input
  292.   int            getch();
  293.   int            getstr(char * str);
  294.   int            scanw(const char *, ...);
  295.  
  296. // input + positioning
  297.   int            mvgetch(int y, int x);
  298.   int            mvgetstr(int y, int x, char * str);
  299.   int            mvscanw(int, int, const char*, ...);
  300.  
  301. // output
  302.   int            addch(const char ch);
  303.   int            addstr(const char * str);
  304.   int            printw(const char * fmt, ...);
  305.   int            inch();
  306.   int            insch(char c);
  307.   int            insertln();
  308.  
  309. // output + positioning
  310.   int            mvaddch(int y, int x, char ch);
  311.   int            mvaddstr(int y, int x, const char * str);
  312.   int            mvprintw(int y, int x, const char * fmt, ...);
  313.   int            mvinch(int y, int x);
  314.   int            mvinsch(int y, int x, char ch);
  315.  
  316. // borders
  317.   int            box(char vert, char  hor);
  318.  
  319. // erasure
  320.   int            erase();
  321.   int            clear();
  322.   int            clearok(int bf);
  323.   int            clrtobot();
  324.   int            clrtoeol();
  325.   int            delch();
  326.   int            mvdelch(int y, int x);
  327.   int            deleteln();
  328.  
  329. // screen control
  330.   int            scroll();
  331.   int            scrollok(int bf);
  332.   int            touchwin();
  333.   int            refresh();
  334.   int            leaveok(int bf);
  335. #ifndef _no_flushok
  336.   int            flushok(int bf);
  337. #endif
  338.   int            standout();
  339.   int            standend();
  340.  
  341. // multiple window control
  342.   int            overlay(CursesWindow &win);
  343.   int            overwrite(CursesWindow &win);
  344.  
  345.  
  346. // traversal support
  347.   CursesWindow*  child();
  348.   CursesWindow*  sibling();
  349.   CursesWindow*  parent();
  350. };
  351.  
  352.  
  353. inline int CursesWindow::begx()
  354. {
  355.   return w->_begx;
  356. }
  357.  
  358. inline int CursesWindow::begy()
  359. {
  360.   return w->_begy;
  361. }
  362.  
  363. inline int CursesWindow::maxx()
  364. {
  365.   return w->_maxx;
  366. }
  367.  
  368. inline int CursesWindow::maxy()
  369. {
  370.   return w->_maxy;
  371. }
  372.  
  373. inline int CursesWindow::height()
  374. {
  375.   return maxy() - begy() + 1;
  376. }
  377.  
  378. inline int CursesWindow::width()
  379. {
  380.   return maxx() - begx() + 1;
  381. }
  382.  
  383. inline int CursesWindow::box(char vert, char  hor)    
  384. {
  385.   return ::box(w, vert, hor); 
  386. }
  387.  
  388. inline int CursesWindow::overlay(CursesWindow &win)         
  389. {
  390.   return ::overlay(w, win.w); 
  391. }
  392.  
  393. inline int CursesWindow::overwrite(CursesWindow &win)       
  394. {
  395.   return ::overwrite(w, win.w); 
  396. }
  397.  
  398. inline int CursesWindow::scroll()                     
  399. {
  400.   return ::scroll(w); 
  401. }
  402.  
  403.  
  404. inline int CursesWindow::touchwin()                   
  405. {
  406.   return ::touchwin(w); 
  407. }
  408.  
  409. inline int CursesWindow::addch(const char ch)         
  410. {
  411.   return ::waddch(w, ch); 
  412. }
  413.  
  414. inline int CursesWindow::addstr(const char * str)     
  415. {
  416.   // The (char*) cast is to hack around prototypes in curses.h that
  417.   // have const missing in the parameter lists.  [E.g. SVR4]
  418.   return ::waddstr(w, (char*)str); 
  419. }
  420.  
  421. inline int CursesWindow::clear()                      
  422. {
  423.   return ::wclear(w); 
  424. }
  425.  
  426. inline int CursesWindow::clrtobot()                   
  427. {
  428.   return ::wclrtobot(w); 
  429. }
  430.  
  431. inline int CursesWindow::clrtoeol()                   
  432. {
  433.   return ::wclrtoeol(w); 
  434. }
  435.  
  436. inline int CursesWindow::delch()                      
  437. {
  438.   return ::wdelch(w); 
  439. }
  440.  
  441. inline int CursesWindow::deleteln()                   
  442. {
  443.   return ::wdeleteln(w); 
  444. }
  445.  
  446. inline int CursesWindow::erase()                      
  447. {
  448.   return ::werase(w); 
  449. }
  450.  
  451. inline int CursesWindow::getch()                      
  452. {
  453.   return ::wgetch(w); 
  454. }
  455.  
  456. inline int CursesWindow::getstr(char * str)           
  457. {
  458.   return ::wgetstr(w, str); 
  459. }
  460.  
  461. inline int CursesWindow::inch()                       
  462. {
  463.   return winch(w); 
  464. }
  465.  
  466. inline int CursesWindow::insch(char c)               
  467. {
  468.   return ::winsch(w, c); 
  469. }
  470.  
  471. inline int CursesWindow::insertln()                   
  472. {
  473.   return ::winsertln(w); 
  474. }
  475.  
  476. inline int CursesWindow::move(int y, int x)           
  477. {
  478.   return ::wmove(w, y, x); 
  479. }
  480.  
  481.  
  482. inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex)
  483. {
  484.   return ::mvcur(sy, ey, sx,ex);
  485. }
  486.  
  487. inline int CursesWindow::mvaddch(int y, int x, char ch)
  488. {
  489.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch);
  490. }
  491.  
  492. inline int CursesWindow::mvgetch(int y, int x)
  493. {
  494.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w);
  495. }
  496.  
  497. inline int CursesWindow::mvaddstr(int y, int x, const char * str)
  498. {
  499.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str);
  500. }
  501.  
  502. inline int CursesWindow::mvgetstr(int y, int x, char * str)
  503. {
  504.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str);
  505. }
  506.  
  507. inline int CursesWindow::mvinch(int y, int x)
  508. {
  509.   return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w);
  510. }
  511.  
  512. inline int CursesWindow::mvdelch(int y, int x)
  513. {
  514.   return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w);
  515. }
  516.  
  517. inline int CursesWindow::mvinsch(int y, int x, char ch)
  518. {
  519.   return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch);
  520. }
  521.  
  522. inline int CursesWindow::refresh()                   
  523. {
  524.   return ::wrefresh(w); 
  525. }
  526.  
  527. inline int CursesWindow::clearok(int bf)             
  528. {
  529.   return ::clearok(w,bf); 
  530. }
  531.  
  532. inline int CursesWindow::leaveok(int bf)             
  533. {
  534.   return ::leaveok(w,bf); 
  535. }
  536.  
  537. inline int CursesWindow::scrollok(int bf)            
  538. {
  539.   return ::scrollok(w,bf); 
  540. }
  541.  
  542. #ifndef _no_flushok
  543. inline int CursesWindow::flushok(int bf)            
  544. {
  545.   return ::flushok(w, bf); 
  546. }
  547. #endif
  548.  
  549. inline void CursesWindow::getyx(int& y, int& x)       
  550. {
  551.   ::getyx(w, y, x); 
  552. }
  553.  
  554. inline int CursesWindow::standout()                   
  555. {
  556.   return ::wstandout(w); 
  557. }
  558.  
  559. inline int CursesWindow::standend()                   
  560. {
  561.   return ::wstandend(w); 
  562. }
  563.  
  564. inline int CursesWindow::lines()                      
  565. {
  566.   return LINES; 
  567. }
  568.  
  569. inline int CursesWindow::cols()                       
  570. {
  571.   return COLS; 
  572. }
  573.  
  574. inline CursesWindow* CursesWindow::child()
  575. {
  576.   return subwins;
  577. }
  578.  
  579. inline CursesWindow* CursesWindow::parent()
  580. {
  581.   return par;
  582. }
  583.  
  584. inline CursesWindow* CursesWindow::sibling()
  585. {
  586.   return sib;
  587. }
  588.  
  589. #endif /* _G_HAVE_CURSES */
  590. #endif
  591.